// 封装banner轮播图相关的业务代码
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { reqBannerAPI } from '@/api/home.js'

export const useBanner = () => {
    const route = useRoute()
    const bannerList = ref([])
    // 根据路由的name来判断当前页面是哪个页面，首页默认为1，商品分类页为2
    const distributionSite = route.name === 'Home' ? '1' : route.name === 'Category' ? '2' : '1' // 默认为1
    const getBanner = async () => {
        const res = await reqBannerAPI({
            distributionSite: distributionSite
        })
        bannerList.value = res.data.result
    }
    onMounted(() => {
        getBanner().then(() => {
        })
    })
    return {
        bannerList
    }
}
